home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1994 November / Cd Ware (Nro. 2) - Epimundo.iso / DOS / PG / DBPP20.ZIP / EXAMPLE1.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-09  |  1.5 KB  |  64 lines

  1. /*
  2.    DataBase ++ 2.00.
  3.    
  4.    The following example creates a database and fills it with 10 records
  5.    then displays all records on the screen.
  6.  
  7.    Borland compile ( c4fox.lib == your codebase lib for FoxPro files ):
  8.  
  9.       bcc -ml -DS4FOX example1 dbpp200.lib c4fox.lib emu.lib mathl.lib cl.lib
  10. */
  11.  
  12. #include <dbppdata.hpp>             // DataBase++
  13. #include <iostream.h>
  14.  
  15. #define MAX_NAMES    10
  16. #define FNAME        "people.dbf"
  17.  
  18. void main()
  19. {
  20.    int i;
  21.    
  22.    // Create the DBDatabase object with the file name.
  23.    DBDatabase db( FNAME );
  24.  
  25.    // Create a DBStructure object and add fields to it.
  26.    DBStructure dbs;
  27.    dbs.addField( "name", 'C', 20 );
  28.    dbs.addField( "age", 'N', 3 );
  29.  
  30.    // Create the database and open it.
  31.    if ( ! db.create( dbs ) )
  32.    {
  33.       cout << "Error creating file\n";
  34.       exit( 1 );
  35.    }
  36.    
  37.    // Create some names.
  38.    char *names[ MAX_NAMES ] = {
  39.       "Jeff", "Wendy", "Kyle", "Nicole", "Scott",
  40.       "Andy", "Dave", "Bruce", "Done", "Henry"
  41.    };
  42.  
  43.    // Add some records.
  44.    for ( i = 0; i < MAX_NAMES; i++ )
  45.    {
  46.       // Append a blank record.
  47.       db.append();
  48.  
  49.       // Replace a field with a string.
  50.       db.replace( "name", names[ i ] );
  51.  
  52.       // Replace a field with an int.
  53.       db.replace( "age", i * 10 );
  54.    }
  55.  
  56.    // Display all records.
  57.    for ( db.goTop(); !db.eof(); db.skip() )
  58.       cout << db.getString( "name" ) << "   " << db.getInt( "age" ) << endl;
  59.  
  60.    // Close file.
  61.    db.close();
  62. }
  63.  
  64.